<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration Page</title>
<style type="text/css">
	.even {
		background-color: silver;
	}
	.error {
		color: #ff0000;
		font-style: italic;
	}
</style>
</head>
<body>
	<form:form action="add.html" commandName="user">
		<table>
			<tr>
				<td>User Name: </td>
				<td><form:input path="name"/></td>
				<td><form:errors path="name" cssClass="error" /></td>
			</tr>
			<tr>
				<td>Password: </td>
				<td><form:password path="password"/></td>
				<td><form:errors path="password" cssClass="error" /></td>
			</tr>
			<tr>
				<td>Gender: </td>
				<td>
					<form:radiobutton path="gender" value="M" label="M"/>
					<form:radiobutton path="gender" value="F" label="F"/>
				</td>
				<td><form:errors path="gender" cssClass="error" /></td>
			</tr>
			<tr>
				<td>Country: </td>
				<td>
					<form:select path="country">
						<form:option value="0" label="Select" />
						<form:options items="${countryList}" itemValue="countryId"
							itemLabel="countryName"/>
					</form:select>
				</td>
				<td><form:errors path="country" cssClass="error" /></td>
			</tr>
			<tr>
				<td>About you: </td>
				<td><form:textarea path="aboutYou"/></td>
				<td><form:errors path="aboutYou" cssClass="error" /></td>
			</tr>
			<tr>
				<td>Community: </td>
				<td>
					<form:checkboxes items="${communityList}" path="communityList"
						itemValue="key" itemLabel="value"/>
				</td>
				<td><form:errors path="communityList" cssClass="error" /></td>
			</tr>
			<tr>
				<td></td>
				<td colspan="2">
					<form:checkbox path="mailingList" label="Would you like to join
						out mailinglist?" />
				</td>
			</tr>
			<tr>
				<td colspan="3"><input type="submit" value="Register" /></td>
			</tr>
		</table>
	</form:form>
	
	<c:if test="${fn:length(userList) > 0}">
		<table cellpadding="5">
			<tr class="even">
				<th>Name</th>
				<th>Gender</th>
				<th>Country</th>
				<th>About You</th>
			</tr>
			<c:forEach items="${userList}" var="user" varStatus="status">
				<tr class="<c:if test='${status.count % 2 == 0}'>even</c:if>">
					<td>${user.name}</td>
					<td>${user.gender}</td>
					<td>${user.country}</td>
					<td>${user.aboutYou}</td>
				</tr>
			</c:forEach>
		</table>
	</c:if>
	
</body>
</html>